#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//DicomTest.cpp  - Declaration and Implementation of Unit Tests for Dicom.h            
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Feb 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#include "DicomFile.h"

#include <cfixcc.h>


class DicomTest : public cfixcc::TestFixture
{
private:
	BYTE _data[208];

public:

	void Before()
	{
		_data[0] = 0x02;		//1st group = 0x0002 (file meta elements)
		_data[1] = 0x00;
		_data[2] = 0x00;		//element = 0x0000 (length)
		_data[3] = 0x00;
		_data[4] = 0x55;		//VR = UL (not present for all elements)
		_data[5] = 0x4C;
		_data[6] = 0x04;		//lengh of size = 0004 bytes
		_data[7] = 0x00;
		_data[8] = 0xC2;		//length value = 000000C2 (194) bytes
		_data[9] = 0x00;
		_data[10] = 0x00;
		_data[11] = 0x00;
		_data[12] = 0x00;		//first byte of meta elements data
		_data[205] = 0x00;		//last byte of meta elements data
		_data[206] = 0x10;		//2nd group = 0x0010 (patient elements)
		_data[207] = 0x00;		
	}

	void After()
	{

	}


	void TestDicomEndian() 
	{
		CFIXCC_ASSERT_EQUALS( true, O32_HOST_ORDER == O32_LITTLE_ENDIAN);
	}

	void TestDicomTypeSize() 
	{
		size_t val = 0;					//check that this machine uses standard type sizes
		BYTE   byteval = 0x00;
		USHORT ushortval = 0x0000;
		UINT uintval = 0x00000000;

		val = 1;
		CFIXCC_ASSERT_EQUALS( val, sizeof(byteval));
		val = 2;
		CFIXCC_ASSERT_EQUALS( val, sizeof(ushortval));
		val = 4;
		CFIXCC_ASSERT_EQUALS( val, sizeof(uintval));
	}

	void TestDicomGroup() 
	{
		DicomGroup grp;
		grp.b[0] = _data[0];
		grp.b[1] = _data[1];

		CFIXCC_ASSERT_EQUALS( GRP_FILE_META_ELEMENTS, grp.val);

	}

	void TestDicomElement() 
	{
		DicomElement element;
		element.b[0] = _data[2];
		element.b[1] = _data[3];

		CFIXCC_ASSERT_EQUALS( EMT_LENGTH, element.val);

	}

	void TestDicomVR() 
	{
		DicomVR vr;
		vr.b[0] = 'U';
		vr.b[1] = 'L';

		CFIXCC_ASSERT_EQUALS( VR_UL, vr.val);

	}

	void TestDicomLenSize() 
	{
		DicomLenSize lensize;
		lensize.b[0] = _data[6];
		lensize.b[1] = _data[7];
		USHORT val = 0x0004;
		CFIXCC_ASSERT_EQUALS( val, lensize.val);

	}

	void TestDicomLenValue() 
	{
		DicomLenValue lenval;
		lenval.b[0] = _data[8];
		lenval.b[1] = _data[9];

		USHORT val = 0x00C2;
		CFIXCC_ASSERT_EQUALS( val,  lenval.val);
	}
};
//
CFIXCC_BEGIN_CLASS( DicomTest )
  CFIXCC_METHOD( TestDicomEndian )
  CFIXCC_METHOD( TestDicomTypeSize )
  CFIXCC_METHOD( TestDicomGroup )
  CFIXCC_METHOD(  TestDicomElement )
  CFIXCC_METHOD( TestDicomVR ) 
  CFIXCC_METHOD(  TestDicomLenSize )
  CFIXCC_METHOD(  TestDicomLenValue )
CFIXCC_END_CLASS()


//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------
